package com.Iconcat.system.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTimeParser {
    public static LocalDateTime parseTime(String dateString) {
        // Define the input and output date format
        DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss");
        DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        try {
            // Parse the input date string
            LocalDateTime dateTime = LocalDateTime.parse(dateString, inputFormatter);

            // Format the parsed date to the desired output format
            String formattedDateTime = dateTime.format(outputFormatter);

            // Parse the formatted date string to LocalDateTime
            return LocalDateTime.parse(formattedDateTime, outputFormatter);
        } catch (Exception e) {
            // Handle parsing exceptions, e.g., invalid date format
            e.printStackTrace();
            return null;
        }
    }
}
